
package managedbean.CRM.SaleLead;

import entity.CRM.LineItem;
import entity.CRM.SaleQuotation;
import entity.CRM.SaleLead;
import entity.Employee;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.el.ELContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import managedbean.Controller;
import session.stateless.CRM.SaleQuotationBeanLocal;

@ManagedBean(name="viewSaleLeadsQuotations")
@ViewScoped
public class ViewSaleLeadsQuotations implements Serializable{

    public ViewSaleLeadsQuotations() {
    }
    
    @EJB
    private SaleQuotationBeanLocal saleQuotationBeanLocal;
    private SaleLead selectedSaleLead;
    private List<SaleQuotation> selectedSaleQuotations;
    private List<LineItem> lineItems;
    private String statusMessage;
    
    public void initView(PhaseEvent event)
    {
        selectedSaleLead = (SaleLead)FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedSaleLead");            
        selectedSaleQuotations = saleQuotationBeanLocal.getSaleQuotationBySaleLead(selectedSaleLead.getRegistrationNumber());
        System.out.println(selectedSaleQuotations.get(0).getId());
    }

    public SaleLead getSelectedSaleLead() {
        return selectedSaleLead;
    }

    public void setSelectedSaleLead(SaleLead selectedSaleLead) {
        this.selectedSaleLead = selectedSaleLead;
    }

    public SaleQuotationBeanLocal getSaleQuotationBeanLocal() {
        return saleQuotationBeanLocal;
    }

    public void setSaleQuotationBeanLocal(SaleQuotationBeanLocal saleQuotationBeanLocal) {
        this.saleQuotationBeanLocal = saleQuotationBeanLocal;
    }

    public List<SaleQuotation> getSelectedSaleQuotations() {
        return selectedSaleQuotations;
    }

    public void setSelectedSaleQuotations(List<SaleQuotation> selectedSaleQuotations) {
        this.selectedSaleQuotations = selectedSaleQuotations;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }
    
    public List<SaleQuotation> getSaleQuotation(){
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        Controller controller = (Controller) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "controller");
        Employee executive = controller.getEmployee();
        return saleQuotationBeanLocal.getSaleQuotation(executive.getEmployeeId());
    }

}